package com.jmx.hello;

import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;

import com.sun.jdmk.comm.HtmlAdaptorServer;

public class HelloAgent {

	/**
	 * @param args
	 * @throws MalformedObjectNameException 
	 * @throws NotCompliantMBeanException 
	 * @throws MBeanRegistrationException 
	 * @throws InstanceAlreadyExistsException 
	 */
	public static void main(String[] args) throws MalformedObjectNameException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
		MBeanServer server = MBeanServerFactory.createMBeanServer();

		ObjectName helloName = new  ObjectName( "chengang:name=HelloWorld" );

		server.registerMBean(new  Hello(), helloName);

		ObjectName adapterName = new  ObjectName( "HelloAgent:name=htmladapter,port=8082" );

		HtmlAdaptorServer adapter = new  HtmlAdaptorServer();

		server.registerMBean(adapter, adapterName);

		adapter.start();

		System.out.println("start....." );

		}
	
		/**
		　　* 先创建了一个MBeanServer，用来做MBean的容器
		
		　　* 将Hello这个类注入到MBeanServer中，注入需要创建一个ObjectName类
		
		　　* 创建一个AdaptorServer，这个类将决定MBean的管理界面，这里用最普通的Html型界面。AdaptorServer其实也是一个 MBean。
		
		　　* chengang:name=HelloWorld的名字是有一定规则的，格式为：“域名:name=MBean名称”，域名和MBean名称都可以任意取。
		
		　　4、运行HelloAgent，然后打开网页：http://localhost:8082/,单击“name=HelloWorld”链接进入
		 */

}
